/**
 * Created by Ysssssss on 2021/4/21.
 */
import apiType, {
    GET_SHOPPING_MALL_ORDER_LIST,
    GET_SHOPPING_MALL_ORDER_DETAIL,
    GET_SHOPPING_MALL_AFTER_SALES_ORDER_LIST,
    GET_SHOPPING_MALL_AFTER_SALES_ORDER_DETAIL,
} from "@constants/ActionTypes";

const initialState = {
    orderListMap: {},
    orderDetailMap: {},
    afterSalesOrderListMap: {},
    afterSalesOrderDetailMap: {},
}

export default function update(state = initialState, action) {
    const {response, params, payload} = action

    switch (action.type) {
        case apiType(GET_SHOPPING_MALL_ORDER_LIST).success:
            return {
                ...state,
                orderListMap: response,
            }
        case apiType(GET_SHOPPING_MALL_ORDER_DETAIL).success:
            return {
                ...state,
                orderDetailMap: {
                    ...state.orderDetailMap,
                    [response.order_number]: response
                }
            }
        case apiType(GET_SHOPPING_MALL_AFTER_SALES_ORDER_LIST).success:
            return {
                ...state,
                afterSalesOrderListMap: response
            }
        case apiType(GET_SHOPPING_MALL_AFTER_SALES_ORDER_DETAIL).success:
            return {
                ...state,
                afterSalesOrderDetailMap: {
                    ...state.afterSalesOrderDetailMap,
                    [response.apply_number]: response
                }
            }
        default:
            return state
    }
}